#include "CubeTest.h"

CubeTest::CubeTest(HINSTANCE hInstance, std::string winCaption)
	: D3DApp(hInstance, winCaption, D3DDEVTYPE_HAL, D3DCREATE_HARDWARE_VERTEXPROCESSING),
	hexalactere(0),
	trilatere(0)
{
	InitAllVertexDeclaration();

	//trilatere = new Triangle();
	//hexalactere = new Cube();
	grid = new TriGrid(1000, 1000, 0.1, 0.1);

	SetCameraPosition(50, 60, 50);

	OnResetDevice();
}

CubeTest::~CubeTest()
{
	DestroyAllVertexDeclaration();
	delete trilatere;
	delete hexalactere;
}

void CubeTest::OnLostDevice()
{
	D3DApp::OnLostDevice();
}

void CubeTest::OnResetDevice()
{
	D3DApp::OnResetDevice();

	HR(gD3DDevice->SetRenderState(D3DRS_LIGHTING, false));
	HR(gD3DDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE));

	// pour le Alpha
	HR(gD3DDevice->SetRenderState(D3DRS_ALPHAREF, 10));
	HR(gD3DDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER));

	// alpha blend
	HR(gD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE));
	HR(gD3DDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1));
	HR(gD3DDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA));
	HR(gD3DDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA));
}

void CubeTest::Update(double dt)
{
	D3DApp::Update(dt);

	//std::cout << dt << std::endl;
	//
	//if (gDInput->keyPressed(DIK_SPACE))
	//{
	//	std::cout << "Yeah space Pressed!" << std::endl;
	//}
	//
	//if (gDInput->keyReleased(DIK_SPACE))
	//{
	//	std::cout << "Yeah space Release!" << std::endl;
	//}
}

void CubeTest::Draw(ID3DXSprite& sprite, D3DXMATRIX& view, D3DXMATRIX& proj)
{
	HR(gD3DDevice->BeginScene());

	D3DApp::Draw(sprite, view, proj);

	HR(gD3DDevice->EndScene());
	HR(gD3DDevice->Present(0, 0, 0, 0));
}

